﻿@inherits BaseComponent

<Tabs Animated Class="@Class" OnChange="OnTabChange">
    <TabBarExtraContentLeft>
        @Model.Left
    </TabBarExtraContentLeft>
    <ChildContent>
        @if (!string.IsNullOrWhiteSpace(Tabs))
        {
            var tabs = Tabs.Split(',');
            foreach (var item in tabs)
            {
                <TabPane Key="@item" Tab="@item" />
            }
        }
        else if (Model != null && Model.HasItem)
        {
            foreach (var item in Model.Items)
            {
                if (item.Content != null)
                {
                    <TabPane Key="@item.Id" Tab="@Language?.GetTitle(item.Title)">
                        @item.Content
                    </TabPane>
                }
                else
                {
                    <TabPane Key="@item.Id" Tab="@Language?.GetTitle(item.Title)" />
                }
            }
        }
    </ChildContent>
    <TabBarExtraContentRight>
        @Model.Right
    </TabBarExtraContentRight>
</Tabs>

@code {
    [Parameter] public string Class { get; set; }
    [Parameter] public string Tabs { get; set; }
    [Parameter] public TabModel Model { get; set; }
    [Parameter] public Action<string> OnChange { get; set; }

    private void OnTabChange(string tab)
    {
        OnChange?.Invoke(tab);
        Model.OnChange?.Invoke(tab);
    }
}